const middleWare1 = (req, res, next) => {
  console.log('middleWare1');
  next?.()
}
const middleWare2 = (req, res, next) => {
  console.log('middleWare2');
  next?.()
}
const middleWare3 = (req, res, next) => {
  console.log('middleWare3');
  next?.()
}

const middleWares = [middleWare1, middleWare2, middleWare3]

const run = (req, res) => {
  const next = () => {
    const middleWare = middleWares.shift()
    if (middleWare && typeof middleWare === 'function') {
      middleWare(req, res, next)
    }
  }
  next()
}

run({}, {})
